﻿namespace SERFLITEMAX20.Viewer
{
    using SERFLITEMAX20;
    using SERFLITEMAX20.DataObjects;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class frmFilters : Form
    {
        private Button btnFix;
        private Button btnSave;
        private Button button1;
        private IContainer components = null;
        private SortedList<string, List<string>> mfilterObjectList = new SortedList<string, List<string>>();
        private ViewMain mMain = null;
        private MyFilterList mMainList;
        private Panel panel1;
        private TabControl tabControl1;
        private TabPage tabPage1;
        private TabPage tCurTab = null;

        public frmFilters()
        {
            this.InitializeComponent();
        }

        private void btnFix_Click(object sender, EventArgs e)
        {
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            Support.SaveFilterObjectList();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void frmFilters_FormClosing(object sender, FormClosingEventArgs e)
        {
            Support.RefreshFilterObjectList();
        }

        private void InitializeComponent()
        {
            this.panel1 = new System.Windows.Forms.Panel();
            this.btnFix = new System.Windows.Forms.Button();
            this.btnSave = new System.Windows.Forms.Button();
            this.tabControl1 = new System.Windows.Forms.TabControl();
            this.tabPage1 = new System.Windows.Forms.TabPage();
            this.mMainList = new SERFLITEMAX20.Viewer.MyFilterList();
            this.button1 = new System.Windows.Forms.Button();
            this.panel1.SuspendLayout();
            this.tabControl1.SuspendLayout();
            this.tabPage1.SuspendLayout();
            this.SuspendLayout();
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.btnFix);
            this.panel1.Controls.Add(this.btnSave);
            this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
            this.panel1.Location = new System.Drawing.Point(0, 0);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(829, 35);
            this.panel1.TabIndex = 1;
            // 
            // btnFix
            // 
            this.btnFix.Location = new System.Drawing.Point(127, 6);
            this.btnFix.Name = "btnFix";
            this.btnFix.Size = new System.Drawing.Size(105, 23);
            this.btnFix.TabIndex = 0;
            this.btnFix.Text = "Fix";
            this.btnFix.UseVisualStyleBackColor = true;
            this.btnFix.Click += new System.EventHandler(this.btnFix_Click);
            // 
            // btnSave
            // 
            this.btnSave.Location = new System.Drawing.Point(16, 6);
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new System.Drawing.Size(105, 23);
            this.btnSave.TabIndex = 0;
            this.btnSave.Text = "Save";
            this.btnSave.UseVisualStyleBackColor = true;
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // tabControl1
            // 
            this.tabControl1.Controls.Add(this.tabPage1);
            this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabControl1.Location = new System.Drawing.Point(0, 35);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(829, 439);
            this.tabControl1.TabIndex = 2;
            this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged);
            // 
            // tabPage1
            // 
            this.tabPage1.Controls.Add(this.mMainList);
            this.tabPage1.Controls.Add(this.button1);
            this.tabPage1.Location = new System.Drawing.Point(4, 22);
            this.tabPage1.Name = "tabPage1";
            this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage1.Size = new System.Drawing.Size(821, 413);
            this.tabPage1.TabIndex = 0;
            this.tabPage1.Text = "Main";
            this.tabPage1.UseVisualStyleBackColor = true;
            // 
            // mMainList
            // 
            this.mMainList.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mMainList.Location = new System.Drawing.Point(3, 3);
            this.mMainList.Name = "mMainList";
            this.mMainList.Size = new System.Drawing.Size(815, 407);
            this.mMainList.TabIndex = 1;
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(54, 19);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(82, 36);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            // 
            // frmFilters
            // 
            this.ClientSize = new System.Drawing.Size(829, 474);
            this.Controls.Add(this.tabControl1);
            this.Controls.Add(this.panel1);
            this.Name = "frmFilters";
            this.Text = "Filters";
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmFilters_FormClosing);
            this.panel1.ResumeLayout(false);
            this.tabControl1.ResumeLayout(false);
            this.tabPage1.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            TabPage selectedTab = this.tabControl1.SelectedTab;
            bool flag = false;
            if ((selectedTab.Controls.Count == 1) && (selectedTab.Controls[0] is MyFilterList))
            {
                ((MyFilterList) selectedTab.Controls[0]).Initialize(this.mfilterObjectList[selectedTab.Text]);
                flag = true;
            }
            if (this.tCurTab != null)
            {
                ((MyFilterList) this.tCurTab.Controls[0]).Initialize(null);
            }
            if (flag)
            {
                this.tCurTab = selectedTab;
            }
            else
            {
                this.tCurTab = null;
            }
        }

        private void UpdateViewer()
        {
            foreach (string str in this.mfilterObjectList.Keys)
            {
                TabPage page = new TabPage(str);
                MyFilterList list = new MyFilterList();
                list.Dock = DockStyle.Fill;
                page.Controls.Add(list);
                this.tabControl1.TabPages.Add(page);
            }
        }

        public void View(ViewMain pMain)
        {
            this.mMain = pMain;
            if (pMain != null)
            {
                foreach (ViewObject obj2 in this.mMain.Objects.Values)
                {
                    if (obj2.ValidFilter() && !Support.filterObjectList.ContainsKey(obj2.key))
                    {
                        Support.filterObjectList.Add(obj2.key, obj2.GetFilterObject());
                    }
                }
            }
            this.mMainList.Initialize(Support.filterObjectList.Keys);
            foreach (FilterObject obj3 in Support.filterObjectList.Values)
            {
                if (obj3.name.Length > 0)
                {
                    if (!this.mfilterObjectList.ContainsKey(obj3.group))
                    {
                        this.mfilterObjectList.Add(obj3.group, new List<string>());
                    }
                    if (!this.mfilterObjectList[obj3.group].Contains(obj3.key))
                    {
                        this.mfilterObjectList[obj3.group].Add(obj3.key);
                    }
                }
            }
            this.UpdateViewer();
            base.ShowDialog();
        }
    }
}

